using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Viper;

namespace Viper.Opcodes
{
	public class bne : Instruction
	{
		private string sym;
		private Symbol symb;
		public bne (string label)
		{
			sym = label;
			this.Mnemonic = "bne";
			this.Operand = label;
			this.Bytecode = new byte[]{0x0A,4,0,0,0,0};
		}
		public bne(Symbol label)
		{
			symb = label;
			this.Mnemonic = "bne";
			this.Operand = symb.Name;
			this.Bytecode = new byte[]{0x09,4,0,0,0,0};
		}
		public override void Relocate (ref List<Symbol> symbols)
		{
			int rel = 0;
			if(symb != null)
			{
				rel = (int)(symb.Address - ((int)(this.Address) + 6));
			}
			else
			{
				foreach(Symbol s in symbols)
				{
					if(s.Name == sym)
					{
						rel = (int)(s.Address - ((int)(this.Address) + 6));
						break;
					}
				}
			}
			byte[] val = System.BitConverter.GetBytes(rel);
			this.Bytecode = new byte[]{0x0A,4,val[0],val[1],val[2],val[3]};
		}
	}
	
}